<!DOCTYPE html>
<html lang="en">
<head>
    {{include file="lib/page_head" /}}
    <style>
        table th{word-wrap:break-word;word-wrap:break-word;word-break:break-all;font-size:12px!important;}
        table td{word-wrap:break-word;word-wrap:break-word;word-break:break-all;}
        #edit_info .form-beautify-select{display:block;width: 100%!important;}
        .form-group{margin-bottom: 5px!important;}
    </style>
</head>
<body >

<!-- Preloader -->
<div id="preloader" style="display: none;">
    <div id="status"><i class="fa fa-spinner fa-spin"></i></div>
</div>

<section>
    {{include file="lib/page_left" /}}
    <div class="mainpanel">

        {{include file="lib/page_header" /}}

        <div class="contentpanel" >
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-btns">
                        <a href="" class="panel-close">×</a>
                        <a href="" class="minimize">−</a>
                    </div>
                    <h4 class="panel-title">后台用户列表</h4>
                </div>
                <div class="panel-body">
                    <div class="form-inline"  id="info_list">
                        <div class="btn-group">
                            <button class="btn btn-primary" type="button" onclick="edit_info(0)">增加</button>
                            <button class="btn btn-primary" type="button" onclick="location.href = location.href;">刷新</button>
                        </div>

                        <div class="layui-form-item" style="margin-top:10px;">
                            <form class="layui-form" id="search_form" action="" onsubmit="return false;">
                                <div class="form-group">
                                    <label >客户名称</label>
                                    <input class="form-control" name="user_name"  autocomplete="off" type="text">

                                </div>


                                <div style="display: inline-block;clear: both;">
                                    <button class="btn btn-primary" onclick="search()">查询</button>
                                    <button class="btn btn-default" onclick="search_reset()">取消</button>
                                </div>
                            </form>

                        </div>
                    </div>

                </div>
            </div>
        </div><!-- contentpanel -->

    </div><!-- mainpanel -->
    {{include file="lib/page_right" /}}
</section>

<div style="display: none;" id="edit_info">
    <form class="layui-form" action="">
        <input name="id" value="0" type="hidden">
        <div class="form-group">
            <label > 登录账号<span style="color:red;">*</span></label>
            <input type="text" name="user_name"  placeholder="登录账号" class="form-control" >
        </div>
        <div class="form-group">
            <label > 真实姓名<span style="color:red;">*</span></label>
            <input type="text" name="real_name"  placeholder="真实姓名" class="form-control" >
        </div>
        <div class="form-group">
            <label > 手机号<span style="color:red;">*</span></label>
            <input type="text" name="mobile"  placeholder="手机号" class="form-control" >
        </div>
        <div class="form-group">
            <label > 岗位角色<span style="color:red;">*</span></label>
            <select name="role_list" class="select6"  style="width:80%" multiple="multiple">
                {{foreach $role_list as $val }}
                <option value="{{$val.id}}">{{$val.role_name}}</option>
                {{/foreach}}
            </select>
        </div>

        <div  class="form-group">
            <label >代理</label>
            <select class="select5" name="agent_id" data-search="true" data-ignore="true">
                <option value="0">请选择</option>
                {{foreach $agent_list as $val }}
                <option value="{{$val.id}}">{{$val.agent_name}}</option>
                {{/foreach}}
            </select>
        </div>
        <div  class="form-group">
            <label >企业</label>
            <select class="select5" name="company_id" data-search="true" data-ignore="true">
                <option value="0">请选择</option>
                {{foreach $company_list as $val }}
                <option value="{{$val.id}}">{{$val.name}}</option>
                {{/foreach}}
            </select>
        </div>
        <div  class="form-group">
            <label > 登录状态</label>
            <select class="select5" name="status">
                <option value="0">正常</option>
                <option value="1">禁用</option>
            </select>
        </div>
        <div class="form-group">
            <label > 登录密码</label>
            <input type="text" name="password"  placeholder="登录密码" class="form-control" data-ignore="true">
        </div>

    </form>
</div>

<script src="../js/jquery-1.11.1.min.js"></script>
<script src="../js/jquery-migrate-1.2.1.min.js"></script>
<script src="../js/jquery-ui-1.10.3.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/jquery.sparkline.min.js"></script>
<script src="../js/toggles.min.js"></script>
<script src="../js/jquery.cookies.js"></script>
<script src="../js/jquery.tmpl.js"></script>
<script src="../js/custom.js"></script>
<script src="../layui/layui.js"></script>
<script src="../js/jquery.gritter.min.js"></script>
<script src="../js/form.beautify.js?t={{$version}}"></script>
<script src="../js/commen.js?t={{$version}}"></script>
<script src="../js/datatables.js?t={{$version}}"></script>
<link href="../css/ley.dialog.css" rel="stylesheet">
<script src="../js/ley.dialog.js?t={{$version}}"></script>
<script>
    function formatState (state) {
        if (!state.id) { return state.text; }
        var $state = $(
            '<span><span class="fa ' + state.element.value.toLowerCase() + '"></span> ' + state.text + '</span>'
        );
        return $state;
    };
    layui.use(['layer','laypage',"element"], function(){
        $("#info_list").datatables({
            idField: 'order_no',
            mobile_field:["ck","user_name","agent_name","status"],
            columns:[
                {field:'ck',checkbox:true },
                {field:'id',title:'编号',width:50},
                {field:'user_name',title:'登录账号',width:100},
                {field:'mobile',title:'手机号',width:100},
                {field:'real_name',title:'真实姓名',width:100},
                {field:'agent_name',title:'代理',width:100},
                {field:'company_name',title:'企业',width:100},
                {field:'ip',title:'IP',width:100},
                {field:'role_list',title:'权限角色',width:100},
                {field:'status',title:'状态',width:30,formatter:function (value,row,index) {
                        if(value===1){
                            return "禁用";
                        }else{
                            return "正常";
                        }
                    }},
                {field:'ctime',title:'时间',width:50, formatter: function (value, row, index) {return getLocalTime(value) + "";}},
                {field:'operation',title:'操作',width:30,formatter:function (value,row,index) {
                        var text = "";
                        text += '<div class="btn-group"> ';
                        text += '<a data-toggle="dropdown" class="dropdown-toggle"> ';
                        text += '<i class="fa fa-cog"></i> ';
                        text += '</a> ';
                        text += '<ul role="menu" class="dropdown-menu pull-right"> ';
                        text +='<li><a href="javascript:void 0;" onclick="edit_info(\''+row.id+'\')">编辑</a></li> ' ;

                        text +='</ul> ';
                        text +='</div>';
                        return text;
                    }}
            ],
            ajax:{
                url:"/adminlist/ajax_admin_list",
                parems:get_search_data(),
                callback:function (msg) {
                    check_table_list_data(msg);
                    check_parent_height();
                }
            }
        });
    });





    function edit_info(id) {
        $("#edit_info form")[0].reset();
        $("#edit_info #product_list").empty();
        $("#edit_info").find("input[name='id']").val(0);
        $("#edit_info").find("select[name='status']").val(0).trigger("change");

        if(id)
        {
            AjaxCommen("GET","/adminlist/ajax_admin_info",{id:id},function (msg) {
                if (!msg.error)
                {
                    $("#edit_info input[type!='radio'],#edit_info select,#edit_info textarea").each(function () {
                        var name = $(this).attr("name");

                        if(name&&msg.data[name]!==undefined)
                        {
                            $(this).val(msg.data[name]);

                        }

                        if($(this).is("select"))
                        {
                            $(this).trigger("change");
                        }
                    });
                    // console.log($("#edit_info select[name='role_list']").val());
                    $("#edit_info input[name='id']").val(msg.data.id);

                    open_info();
                }
            });
        }else{
            open_info();
        }
    }
    function open_info()
    {
        $("#edit_info select").trigger("change");
        openDialog2({title:"用户信息",area: ['400', "500"],content:$("#edit_info"),clone:true,before:function (layero) {
            },
            yes:function (index,layero) {
                var data = {};
                var is_false = false;

                $("input[type!='radio'],select,textarea,input[type='radio']:checked",layero).each(function () {
                    var name = $(this).attr("name");
                    var ignore = $(this).attr("data-ignore");
                    if(name)
                    {
                        var value = $(this).val();

                        if(value)
                        {
                            data[name] = value;
                            $(this).parents(".form-group").removeClass("has-error");
                        }else{
                            if (ignore != "true")
                            {
                                $(this).parents(".form-group").addClass("has-error");
                                is_false = true;
                            }
                        }
                    }
                });
                if(is_false)
                {
                    return false;
                }
                AjaxCommen("POST","/adminlist/ajax_admin_info_save",data,function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        layero.close();
                        search();
                    }
                });
            }
        });
    }
    function get_search_data()
    {
        var data = {};
        data["user_name"] = $("#search_form input[name='user_name']").val();
        return data;
    }
    function search()
    {
        var data = get_search_data();
        console.log(data)
        $("#info_list").setParems(data);
        $("#info_list").reload();
    }
    function search_reset() {
        $("#search_form")[0].reset();
        search();
    }



</script>

</body>
</html>